package com.canbot.u05.activity.training;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.canbot.u05.R;
import com.canbot.u05.bean.TrainingTask;
import com.canbot.u05.glide.GlideApp;

import java.util.List;

public class PostArticleImgAdapter extends RecyclerView.Adapter<PostArticleImgAdapter.MyViewHolder> {

        private List<TrainingTask> mDatas;

        private final LayoutInflater mLayoutInflater;

        private final Context mContext;


        public PostArticleImgAdapter(Context context, List<TrainingTask> datas) {
                this.mDatas = datas;
                this.mContext = context;
                this.mLayoutInflater = LayoutInflater.from(context);
        }

        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                return new MyViewHolder(mLayoutInflater.inflate(R.layout.item_stafftraining_activity, parent, false));
        }

        @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {

                if(mDatas.size()-1==position){
                        holder.textViewNum.setText("");
                        holder.textView.setText("添加任务步骤");
                        GlideApp.with(mContext).asDrawable()
                                .load(R.drawable.stafftraining_add)
                                .diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
                }else{
                        holder.textViewNum.setText(position+1+"");
                        holder.textView.setText("任务步骤"+(position+1));
                        GlideApp.with(mContext).asDrawable().load(mDatas.get(position).getBigBg())
                             .diskCacheStrategy(DiskCacheStrategy.RESOURCE).into(holder.imageView);
                }


        }

        public void setmDatas(List<TrainingTask> updateDate){
                mDatas = updateDate;
        }

        @Override
        public int getItemCount() {
                return mDatas == null ? 0 : mDatas.size();
        }

        public static class MyViewHolder extends RecyclerView.ViewHolder {

                ImageView imageView;

                TextView textViewNum;

                TextView textView;

                public MyViewHolder(View itemView) {
                        super(itemView);
                        imageView = (ImageView) itemView.findViewById(R.id.sdv);
                        textViewNum = (TextView)itemView.findViewById(R.id.text_num1);
                        textView = (TextView) itemView.findViewById(R.id.text_1);
                }
        }


}
